import cv2
import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":
    img_gray = cv2.imread("../images/test_write.jpg", cv2.IMREAD_GRAYSCALE)
    img = cv2.imread("../images/test_write.jpg", cv2.IMREAD_COLOR)
    print(img_gray.shape)
    blur = cv2.blur(img_gray, (3, 3))
    print(blur.shape)
    kernel = np.ones((3, 3), np.uint8)
    erosion = cv2.erode(img_gray, kernel, iterations=1)
    # tophat = cv2.morphologyEx(img_gray, cv2.MORPH_TOPHAT, kernel)
    print(erosion.shape)
    # Sobel Operator
    sobelx = cv2.Sobel(img_gray, cv2.CV_64F, 1, 0, ksize=3)
    sobelx = cv2.convertScaleAbs(sobelx)
    sobely = cv2.Sobel(img_gray, cv2.CV_64F, 0, 1, ksize=3)
    sobely = cv2.convertScaleAbs(sobely)
    sobelxy = cv2.addWeighted(sobelx, 0.5, sobely, 0.5, 0)
    # Scharr Operator
    scharrx = cv2.Scharr(img_gray, cv2.CV_64F, 1, 0)
    scharrx = cv2.convertScaleAbs(scharrx)
    scharry = cv2.Scharr(img_gray, cv2.CV_64F, 0, 1)
    scharry = cv2.convertScaleAbs(scharry)
    scharrxy = cv2.addWeighted(scharrx, 0.5, scharry, 0.5, 0)
    # Laplacian Operator
    laplacian = cv2.Laplacian(img_gray, cv2.CV_64F)
    laplacian = cv2.convertScaleAbs(laplacian)
    result = np.hstack((img_gray, sobelxy, scharrxy, laplacian))
    cv2.imshow("result", result)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
